package cn.szzsi._admin;

import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.Payment;
import com.jfinal.kit.StrKit;

import java.util.List;

/**
 * 商户后台类 - 支付
 * Created by yuanzhneg on 2016/10/13.
 */
public class PaymentController extends BaseAdminController<Payment> {
    private String shopId;
    // 列表
    public void list() {
        String status = getPara("status","yzf");
        if(status.equalsIgnoreCase("yzf")){
            render("payment_manage_list_yzf.html");
        }else if (status.equalsIgnoreCase("wzf")){
            render("payment_manage_list_wzf.html");
        }

    }
    //ajax list
    public void ajaxlist(){
        shopId=getAttr("shopId");
        String status = getPara("status","yzf");
        String sql="select p.*,m.code from mall_payment p LEFT JOIN mall_orders o  on p.order_id=o.id LEFT JOIN mall_member m on o.member_id=m.id where 1=1 ";
        if(status.equalsIgnoreCase("yzf")){
            sql+="and p.paymentStatus='3' ";
        }else if (status.equalsIgnoreCase("wzf")){
            sql+="and p.paymentStatus='0' ";
        }
        sql+="and p.uid = '"+shopId+"'  order by p.createDate desc";
        List<Payment> lp = Payment.dao.find(sql);
        renderJson(lp);
    }

    // 查看
    public void view(){
        id = getPara("id","");
        if(StrKit.notBlank(id)){
            setAttr("payment", Payment.dao.findById(id));
            Payment.dao.findById(id).getPaymentStatus();
            render("payment_manage_view.html");
        }
    }

    // 删除
    public void delete(){
        ids = getParaValues("ids");
        if(ids != null && ids.length > 0){
            for(String id : ids){
                if(Payment.dao.deleteById(id)){
                    ajaxJsonSuccessMessage("删除成功！");
                }else{
                    ajaxJsonErrorMessage("删除失败！");
                }
            }
        }
    }
}
